{% extends "base.html" %}

{% block container_class_name %}settings{% endblock %}
{% block container %}

  {% ifequal step '3'  %}
    <div class="subhead">
      <div class="container">
        <h2 class="heading">{{ user.username }}</h2>
      </div>
    </div>
  {% else %}
    <div class="subhead">
      <div class="container">
        <h2 class="heading">更改密码<span class="note">email是您进行帐号验证的唯一途径</span></h2>
      </div>
    </div>
  {% endifequal %}

  <div class="content">
    <div class="container">

      {% ifequal step '0' %}
        <div class="inner resetpwd">
          <form class="well form-inline" action="/resetpassword/0/" method="post">
            {% if error %}
              <div class="alert">
                <a data-dismiss="alert" class="close"><i class="icon-remove"></i></a>
                <p><strong>出错了！</strong> {{ error }}</p>
              </div>
            {% endif %}
            <fieldset>
              {% csrf_token %}
              {{ resetpasswordForm0.email }}
              {{ resetpasswordForm0.captcha }}
              <button class="btn" type="submit">更改</button>
            </fieldset>
          </form>
        </div>
      {% endifequal %}

      {% ifequal step '1' %}
        <div class="inner resetpwd">
          <h3 class="heading">已经发送重置密码邮件，请在半小时内重置，部分运营商会拦截邮件，注意查收</h3>
          <p class="alert alert-error">如果发送邮件失败，请联系<a href="mailto:support@gitshell.com">support@gitshell.com</a> 或者 <a target="_blank" href="http://weibo.com/gitshell"><img src="/static/img/sina_logo.png"/>gitshell</a></p>
        </div>
      {% endifequal %}

      {% if step|length > 1 %}
        <div class="inner resetpwd">
          <form class="form-horizontal" action="" method="post">
            {% if error %}
              <div class="alert alert-error">
                <a data-dismiss="alert" class="close"><i class="icon-remove"></i></a>
                <p><strong>出错了！</strong> {{ error }}</p>
              </div>
            {% endif %}
            <fieldset>
              {% csrf_token %}
              <div class="control-group">
                <label for="password" class="control-label">新密码</label>
                <div class="controls">
                  {{ resetpasswordForm1.password }}
                </div>
              </div>
              <div class="control-group">
                <div class="controls"><button id="resetpasswordSubmit" class="btn btn-primary" type="submit">更改</button></div>
              </div>
            </fieldset>
          </form>
        </div>
      {% endif %}

      {% ifequal step '3' %}
        <div class="inner resetpwd">
          <p class="alert alert-info">哎呀，您可不要再忘了密码了</p>
        </div>
      {% endifequal %}

      {% ifequal step '4' %}
          <div class="inner resetpwd">
            <p class="alert alert-error">设置失败，可能是url Token过期，请重新通过<a href="/resetpassword/0/">重置</a>获取激活url，如果这种情况持续出现，请联系<a href="mailto:support@gitshell.com">support@gitshell.com</a> 或者 <a target="_blank" href="http://weibo.com/gitshell"><img src="/static/img/sina_logo.png"/>&nbsp;gitshell</a></p>
          </div>
      {% endifequal %}

    </div>
  </div>

{% endblock %}

{% block js %}
  <script>
    $(function(){
        var md5_user_passwd = function() {
            $('#password').val(window.md5($('#password').val()));
        },
        resetpassword0_init = function() {
            $('#email').attr('placeholder', '输入邮箱');
            $('#captcha1').attr('placeholder', '输入验证码');
        };
        resetpassword1_init = function() {
            $('#password').attr('placeholder', '密码，包含数字和字母');
        };
    {% ifequal step '0' %}
        resetpassword0_init();
    {% endifequal %}
    {% if step|length > 1 %}
        resetpassword1_init();
    {% endif %}
        $('#resetpasswordSubmit').on('click', md5_user_passwd);
    });
  </script>
{% endblock %}
